//
// Created by cen on 2025/8/16.
//


#include <iostream>

#include <functional>
using namespace std;

int add(int a, int b) {
    return a + b;
}

class Functor {
public:
    int operator()(int a, int b) {
        return a + b;
    }
};

class Add {
public:
    static int intAdd(int a, int b) {
        return a + b;
    }

    double doubleAdd(double a, double b) {
        return a + b;
    }
};

int main() {
    //1、包装函数指针（函数名）
    function<int(int, int)> func1 = add;
    cout << func1(1, 2) << endl;

    //2、包装仿函数（函数对象）
    function<int(int, int)> func2 = Functor();
    cout << func2(1, 2) << endl;

    //3、包装lambda表达式
    function<int(int, int)> func3 = [](int a, int b) { return a + b; };
    cout << func3(1, 2) << endl;

    //4、类的静态成员函数
    //function<int(int, int)> func4 = Plus::plusi;
    function<int(int, int)> func4 = &Add::intAdd; //&可省略
    cout << func4(1, 2) << endl;

    //5、类的非静态成员函数
    function<double(Add, double, double)> func5 = &Add::doubleAdd; //&不可省略
    cout << func5(Add(), 1.1, 2.2) << endl;
    return 0;
}
